package net.hn.hnms.biz.safety.location.repository;

import net.hn.hnms.biz.safety.location.domain.JxryNowPersonnelinfoEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 智呈物联 pan'sx
 * 2022/9/1 20:09
 * 1.0 version
 */
@Repository
public interface JxryNowPersonnelinfoRepository extends JpaRepository<JxryNowPersonnelinfoEntity,Long> {

    @Query(value = "SELECT t.*,tt.dept_name as dept,tt.duty FROM dwd_jxry_now_personnelinfo t " +
            "JOIN dwd_jxry_base_personnelinfo tt on (t.staff_code=tt.staff_code) " +
            "where data_time=(SELECT max(data_time) from dwd_jxry_now_personnelinfo" +
            " where  CASE when  :mineCode != '' then mine_code = :mineCode else 1=1 end) " +
            " and CASE when  :duty != '' then   tt.duty = :duty else  1=1  end " +
            " and CASE when  :dept != '' then tt.dept_name = :dept else 1=1 end  " +
            " and CASE when  :mineCode != '' then tt.mine_code = :mineCode else 1=1 end  " +
            " and CASE when  :mineCode != '' then t.mine_code = :mineCode else 1=1 end  " +
            " and CASE when  :staffName != '' then t.staff_name like CONCAT(:staffName, '%') else 1=1 end " +
            " and CASE when  :leader != '' then t.mine_leader = :leader else 1=1 end ", nativeQuery = true)
    Page<JxryNowPersonnelinfoEntity> getPageDate(@Param("duty") String duty, @Param("dept") String dept,@Param("staffName")String staffName,@Param("leader") String leader, Pageable pageable,@Param("mineCode")String mineCode);

    List<JxryNowPersonnelinfoEntity> findByStationCodeIn(List<String> stationCodes);
}
